auto();
requestScreenCapture();
var zh = images.read("/sdcard/立即领取.png");
var wx = images.read("/sdcard/微信.png");
var str = rawInput("请输入您的账号");

var users = str.split("\n");
var num = 0;
var num1 = 0;
var r="";
var url=new Array();
url[0]="https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=463783639952396032&shareTo=weixin&shareFrom=appmarket#/";
url[1]="https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=517380660915090432&shareTo=weixin&shareFrom=appmarket#/";
url[2]="https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=545633931853040256&hwFullScreen=1&shareTo=weixin&shareFrom=appmarket";
url[3]="https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=512807300642120960&shareTo=weixin&shareFrom=appmarket#/";
url[4]="https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=521525060456944128&shareTo=weixin&shareFrom=appmarket#/";
url[5]="https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=551243279643971328&hwFullScreen=1&shareTo=weixin&shareFrom=appmarket";
url[6]="https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=559325707369459840&hwFullScreen=1&shareTo=com.tencent.minihd.qq&shareFrom=appmarket";
var options = ["邀请1", "邀请2", "邀请3", "邀请4","邀请5","邀请6","邀请7"]
var c= dialogs.select("请选择邀请序号", options);

for (var i = 0; i < users.length; i++) {
    launchApp("设置");
    toast(users[i]);
   
    outerloop:
    while (1) {
        sleep(1000);
        //退出华为账号***********************************************************
        if (text("华为帐号、付款与账单、云空间等").findOne(100)) {

            while (!click("华为帐号、付款与账单、云空间等"));
          if (text("取消").findOne(3000)) {
            while (!click("取消"));
           sleep(3000);
            click("取消");
            }
            while (!click("退出帐号"));
            //var button = className("android.widget.Button").text("退出帐号").findOne(100000);
            while (!click("退出帐号",1));
            
           

        }
        //**************************************** */
        //登陆华为账号*************************************************
        if (text("登录华为帐号").findOne(100)) {
            sleep(2000);
            while (!click("登录华为帐号"));
            sleep(2000);
            while (!setText(0, users[i]));
            while (!input(1, "Hw@12576"));
            sleep(2000);
            var dl = text("登录").findOne(2000);
            if (dl) {
                dl.click();
                
            }
           
            innerloop:
            while (!text("为了帐号安全，需绑定安全手机号，用于验证身份。").exists()) {
               dl = textContains("帐号或密码错误").findOne(500);
            if (dl) {
                console.log("帐号或密码错误");
                num1+=1;
                home();
                break outerloop;
            }
             //账号绑定手机号，换下一个账号并记录
            if (text("选择其他验证方式").findOne(300)) {
              console.log("选择其他验证方式");
                num1 += 1;
                home();
                break outerloop;
            }
                dl = text("获取验证码").findOne(500);
                if(dl){
                while (!click("获取验证码"));
                r = http.get("http://shopapi.wwsd.top/api/email/addEmail?account=" + users[i] + "&password=Hw@12576");
                while (1) {
                     
                     r = http.get("http://shopapi.wwsd.top/api/email/getRead?email=" + users[i] + "&password=Hw@12576");
                     r = r.body.string();
                     console.log("正在获取验证码");
                    click("重新获取");
                    if (r.search("<b>") != -1) {

                        var code = r.split("<b>")[1].split("<")[0];
                        toast(code);
                        while (!setText(0, code));
                        while (!click("确定"));
                        break;

                    }
                    sleep(5000);
                    
                }
              }
                dl = text("同意").findOne(100);
                if (dl) {
                    console.log("同意");
                    dl.click();
                }
                
             
            }
              dl = text("取消").findOne(10000);
                if (dl) {
                    console.log("取消");
                    dl.click();
                }
                  dl = text("取消").findOne(10000);
                if (dl) {
                    console.log("取消");
                    dl.click();
                }
            app.openUrl(url[c]);
            console.log("打开浏览器");

}


               
    //注册地香港时强行停止////////////////////////////
    if (textContains("您当前选择的国家/地区为").findOne(100)) {
        while (!click("确定"));
        console.log("强行停止");
        while (!openAppSetting(getPackageName("华为应用市场")));
        while (!click("强行停止"));
        while (!click("强行停止"));
        sleep  (2000);
        app.openUrl(url[c]);
        sleep(1000);
      
    }
    //同意浏览器协议
    if (textContains("华为浏览器用户协议").findOne(100)) {
        console.log("同意浏览器协议");
        while (!click("同意"));
    }
    //同意浏览器跳转应用市场
    if (textContains("请求打开").findOne(100)) {
        click(900, 2100);
        console.log("同意浏览器跳转应用市场");
    }
    
    if (text("开始种花").findOne(100)) {
        click("开始种花");
    }
    p = images.findImageInRegion(captureScreen(), zh, 0, 555, 1080, 1230);
    if (p) {
        console.log("立即领取");
        click(550, 1330);
        sleep(500);
        click(550, 1330);
        sleep(500);
        click(550, 1330);
        sleep(500);
        click(550, 1330);
        sleep(500);
    }
   p = images.findImageInRegion(captureScreen(), zh, 0, 555, 1080, 1230);
    if (p) {
        console.log("立即领取");
        click(500, 1480);
        sleep(500);
        click(500, 1480);
        sleep(500);
        click(500, 1480);
        sleep(500);
        click(500, 1480);
        }
    if (text("通知栏显示活动、中奖、评论等消息").findOne(100)) {
        console.log("同意应用市场协议");
        while (!click("同意"));
    }
    if (text("内容详情请参阅最新的关于华为应用市场与隐私的声明。").findOne(100)) {
        console.log("同意应用市场协议");
        while (!click("同意"));
    }
    if (text("30g").findOne(100)) {
        console.log("发现30g");
        sleep(1000);
        click(900, 2000);
        click(900, 2000);
        sleep(3000);
        openAppSetting(getPackageName("华为应用市场"));
        while (!click("存储"));
        while (!click("删除数据"));
        while (!click("确定"));
        sleep(1000);
        home();
        break;

    }

    if (text("20g").findOne(100)) {
        console.log("发现20g");
        num += 1;
        sleep(3000);
        openAppSetting(getPackageName("华为应用市场"));
        while (!click("存储"));
        while (!click("删除数据"));
        while (!click("确定"));
        sleep(1000);
        home();
        break;
    }

}
}
c+=1;
alert("邀请"+c+"邀请完毕，有" + num + "个账号已使用，"+num1+"个账号已绑定手机号，记得视频签到。");
console.log("邀请"+c+"邀请完毕，有" + num + "个账号已使用，"+num1+"个账号已绑定手机号，记得视频签到。");
//==�号，记得视频签到。");
//==